import '../../../../heathManege/ScoreManagement/components/ModalseeS2/ModalseeS2.css'
import './ModaladdE.css'
import React, { useState } from 'react';
import { Modal, Button } from 'antd'
import {
    Form,
    Input,
    Radio,
} from 'antd';
import http from '../../../../../utils/http';
const ModaladdE = (props) => {
    // 添加
    const [isModalVisible4, setIsModalVisible4] = useState(false);

    const showModal4 = () => {
        setIsModalVisible4(true);
    };


    let format = function (time, format) {   //前台获取时间，转化为国际时间，可以当做工具使用
        let t = new Date(time);
        let tf = function (i) { return (i < 10 ? '0' : "") + i };
        return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function (a) {
            switch (a) {
                case 'yyyy':
                    return tf(t.getFullYear());
                    break;
                case 'MM':
                    return tf(t.getMonth() + 1);
                    break;
                case 'mm':
                    return tf(t.getMinutes());
                    break;
                case 'dd':
                    return tf(t.getDate());
                    break;
                case 'HH':
                    return tf(t.getHours());
                    break;
                case 'ss':
                    return tf(t.getSeconds());
                    break;
            }
        })
    }
    
    let dateNow = new Date();
    let date = format(dateNow, 'yyyy-MM-dd HH:mm:ss');



    const [Question_name, setQuestion_name] = useState()
    const onChange_Question_name = e => {
        console.log(e.target.value);
        setQuestion_name(e.target.value)
    }

    const [answer1, setanswer1] = useState()
    const onChange_answer1 = e => {
        console.log(e.target.value);
        setanswer1(e.target.value)
    }

    const [answer2, setanswer2] = useState()
    const onChange_answer2 = e => {
        console.log(e.target.value);
        setanswer2(e.target.value)
    }

    const [State, setState] = useState(1)
    function addState(value) {
        console.log(`状态 `, value.target.value);
        setState(value.target.value)
    }

    const handleOk4 = () => {
        setIsModalVisible4(false);
        http({
            url: '/EvaluationConfiguration/add',
            method: 'post',
            data: {
                Question_name: Question_name,
                answer1: answer1,
                answer2: answer2,
                State: State,
                creatTime:date
            }
        }).then((res) => {
            if (res) {
                props.fn();
                props.pagingtotal();
            }
        })
    };


    const handleCancel4 = () => {
        setIsModalVisible4(false);
    };
    // 模态框title
    const CustomTitle4 = () => {
        return (
            <div className='CustomTitle_title'>
                添加
            </div>
        )
    }
    return (
        <div>
            <Button onClick={showModal4} size="small" className="h1_shuru_c4" type="primary">添加
            </Button>
            <Modal destroyOnClose cancelText='返回' okText='确认' width="715px" title={<CustomTitle4 ></CustomTitle4>} visible={isModalVisible4} onOk={handleOk4} onCancel={handleCancel4} footer={[
                <Button id="ModalseeS3Btn1" key="back" onClick={handleCancel4}>返回</Button>,
                <Button id="ModalseeS3Btn2" key="submit" type="primary" onClick={handleOk4}>
                    确认
                </Button>,
            ]}>
                <div className="ModalseeC2">
                    <Form preserve={false} className="comment">
                        <p>问题名称:</p>
                        <Form.Item>
                            <Input placeholder="请输入问题名称" onChange={onChange_Question_name} />
                        </Form.Item>
                        <p>答案一：</p>
                        <Form.Item>
                            <Input placeholder="请输入答案" onChange={onChange_answer1} />
                        </Form.Item>
                        <p>答案二：</p>
                        <Form.Item>
                            <Input placeholder="请输入答案" onChange={onChange_answer2} />
                        </Form.Item>
                        <p className="status">状态:</p>
                        <Form.Item >
                            <Radio.Group name="radiogroup" onChange={addState} defaultValue={1}>
                                <Radio value={1}>启用</Radio>
                                <Radio value={2}>禁用</Radio>
                            </Radio.Group>
                        </Form.Item>
                    </Form>
                </div>
            </Modal>
        </div>
    );
};
export default ModaladdE;